home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / e / amigae30a_fr.lha / AmigaE30f / Sources / Class / Hash / hashtest.e < prev   
Encoding:
Text File  |  1994-11-27  |  1.6 KB  |  58 lines

  1. /* fonction test de 'hashing'
  2.  
  3. les identificateurs sont généré par 10, 100, 1000, qui sont coupé en
  4. table de taille 1, 211, 941, 3911 et 16267. Affiché sont les nombres moyens
  5. de StrCmp nécéssaire pour trouver n'importe lequel de ces identificateurs.
  6.  
  7. */
  8.  
  9. MODULE 'class/hash'
  10.  
  11. RAISE "MEM" IF String()=NIL
  12.  
  13. PROC main()
  14.   DEF heavy:PTR TO LONG,a,b,l,num:PTR TO LONG,t=NIL:PTR TO hashtable,
  15.       c,ll,n,h,link:PTR TO hashlink,rs[10]:STRING
  16.   heavy:=[1,HASH_NORMAL,HASH_MEDIUM,HASH_HEAVY,HASH_HEAVIER]
  17.   num:=[10,100,1000]
  18.   l:=genidents(1000)
  19.   WriteF('numidents:')
  20.   FOR b:=0 TO 2 DO WriteF('\t\d\t',num[b])
  21.   WriteF('\ntablesize:\n')
  22.   FOR a:=0 TO 4
  23.     WriteF('[\d]\t\t',heavy[a])
  24.     FOR b:=0 TO 2
  25.       NEW t.hashtable(heavy[a])
  26.       ll:=l
  27.       FOR c:=1 TO num[b]
  28.         n,h:=t.find(ll,EstrLen(ll))
  29.         t.add(NEW link,h,ll,EstrLen(ll))
  30.         ll:=Next(ll)
  31.       ENDFOR
  32.       WriteF('\s[8]\t',RealF(rs,t.calc_hash_spread(),4))
  33.       END t
  34.     ENDFOR
  35.     WriteF('\n')
  36.   ENDFOR
  37. ENDPROC
  38.  
  39. -> génère des identificateurs au hasard
  40.  
  41. PROC genidents(n)
  42.   DEF l=NIL,a,s[100]:STRING,x:PTR TO LONG,len,prt,b,y
  43.   x:=['bla','burp','e_','pom','ti','dom','aap','noot','mies']
  44.   len:=ListLen(x)
  45.   FOR a:=1 TO n
  46.     StrCopy(s,'')
  47.     StrAdd(s,(y:=Rnd(26)+"A") BUT {y}+3,1)
  48.     StrAdd(s,(y:=Rnd(26)+"a") BUT {y}+3,1)
  49.     StrAdd(s,(y:=Rnd(26)+"A") BUT {y}+3,1)
  50.     prt:=Rnd(3)+1
  51.     FOR b:=1 TO prt DO StrAdd(s,x[Rnd(len)])
  52.     StrAdd(s,(y:=Rnd(26)+"A") BUT {y}+3,1)
  53.     StrAdd(s,(y:=Rnd(26)+"a") BUT {y}+3,1)
  54.     StrAdd(s,(y:=Rnd(26)+"A") BUT {y}+3,1)
  55.     l:=Link(StrCopy(String(EstrLen(s)),s),l)
  56.   ENDFOR
  57. ENDPROC l
  58.